fix: ensure assistant message content is never undefined for Gemini compatibility #10559
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes ROO-425: OpenRouter + Gemini "parts field" validation error when assistant message has undefined content.
Problem
When assistant messages contain only
tool_useblocks (no text), thecontentfield was left asundefined. While OpenAI acceptscontent: nullwithtool_calls, Gemini (via OpenRouter) strictly requires every message to have content in the "parts" field.This caused users to encounter a 400 Bad Request error:
Solution
Use empty string fallback (
content ?? "") for assistant message content instead of allowingundefined.Changes
src/api/transform/openai-format.ts: Usecontent ?? ""instead ofcontentsrc/api/transform/__tests__/openai-format.spec.ts: Add test case for Gemini compatibilityTesting
openai-format.spec.tsRelated
Important
Fixes undefined content in assistant messages for Gemini compatibility by using empty string fallback in
convertToOpenAiMessages().tool_useblocks hadundefinedcontent, causing errors with Gemini via OpenRouter.content ?? ""to ensure content is neverundefinedinconvertToOpenAiMessages()inopenai-format.ts.openai-format.spec.tsto verify empty string content for Gemini compatibility.openai-format.spec.tsand across the project.This description was created by
for f6304d4. You can customize this summary. It will automatically update as commits are pushed.